package com.health.viewscontrols.lvyuejl;

import android.content.Intent;
import android.graphics.drawable.BitmapDrawable;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;

import android.support.annotation.RequiresApi;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Spinner;
import android.widget.TextView;

import com.health.R;
import com.health.adapter.QYDoctersAdapter;
import com.health.adapter.SpinnerAdapter;
import com.health.model.LvYueFuWuBean;
import com.health.tablebean.ARCHIVE_BASEINFO;
import com.health.tablebean.BD_ORGANIZE_EMPLOYEE;
import com.health.tablebean.JTYSCustomerDoctorCont;
import com.health.tablebean.JTYS_SignPictureData;
import com.health.tablebean.SBCL_DATA;
import com.health.tools.GlobalConts;
import com.health.tools.ImageTools;
import com.health.viewscontrols.NovaActivity;
import com.health.viewscontrols.NovaApplication;
import com.health.viewscontrols.qyinfo.QianMingActivity;
import com.health.widget.EditTextWithDate;
import com.novabluetooth.services.BluetoothConstant;
import com.novabluetooth.views.ExamHistoryActivity;

import java.io.File;
import java.lang.reflect.Field;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * 履约记录表
 * Created by John on 2019/2/28.
 */

public class LvYueJiLuActivity extends NovaActivity {
    Button btn_back;//返回
    TextView title;//标题
    Button btn_up;//保存
    ARCHIVE_BASEINFO userinfo = null;
    EditTextWithDate ed_date;//服务时间
    TextView lvyue_name;//姓名
    TextView lvYue_age;//年龄
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    EditText lvyueHight;//身高
    EditText lvyueWeight;//体重
    Button lvyueWeightBtn;//
    EditText lvyueTzzs;//体质指数
    EditText lvyueHuxi;//呼吸频率
    EditText lvyueXinlv;//心率
    Button lvyueXinlvBtn;//
    EditText lvyueTiwen;//体温
    Button lvyueTiWenBtn;//
    EditText lvyueXueYaGao;//收缩压
    EditText lvyueXueYaDi;//舒张压
    Button lvyueXueYaBtn;//
    EditText lvyueXueTang;//血糖
    Spinner xuetang_spinner;//血糖下拉
    String xuetangType="1";//血糖类型
    Button lvyueXueTangBtn;
    EditText lvyueJiBing;//现存主要疾病
    EditText lvyueJiBing_beizhu;
    EditText lvyueJkgl;//健康管理
    EditText lvyuejkgy_beizhu;
    EditText lvyueZyqk;//住院情况
    EditText lvyuezyqk_beizhu;
    EditText lvyueYongyao;//用药情况
    EditText yongYao_beizhu;
    EditText lvyueZzqk;//转诊情况
    EditText zhuanzhen_beizhu;
    Spinner lvyuedocName;//医生姓名
    ImageView lvyueDocImg;
    Button lvyueDocBtn;
    TextView lvyueHuanName;//患者姓名
    ImageView lvyueHuanImg;
    Button lvyueHuanBtn;
    EditText docname_beizhu;
    EditText username_beizhu;
    EditText lvyueBeiZhu;//备注

    EditText beiZhu1;//备注1
    EditText beiZhu2;//备注2
    EditText beiZhu3;//备注3

    //口唇
    RadioGroup group_kouchun;
    RadioButton kouchun_hongrun;
    RadioButton kouchun_cangbai;
    RadioButton kouchun_fangan;
    String kouchunStr="1";
    EditText kouchun_qita;
    EditText kouchun_beizhu;
    //齿列
    CheckBox chilie_zhengchuang;
    CheckBox chilie_quechi;
    CheckBox chilie_yuchi;
    CheckBox chilie_yichi;
    String chilieStr="1";
    EditText chilie_qita;
    EditText chilie_beizhu;

    //咽部
    CheckBox yanbu_wuchongxue;
    CheckBox yanbu_chongxue;
    CheckBox yanbu_linba;
    String yanbuStr="1";
    EditText yanbu_qita;
    EditText yanbu_beizhu;
    //听力
    RadioGroup group_tingli;
    RadioButton tingli_yes;
    RadioButton tingli_no;
    String tingliStr="1";
    EditText tingli_qita;
    EditText tingli_beizhu;
    //皮肤
    RadioGroup group_pifu;
    RadioButton pifu_zhengchang;
    RadioButton pifu_chaoshi;
    RadioButton pifu_cangbai;
    RadioButton pifu_fagan;
    RadioButton pifu_huangran;
    String pifuStr="1";
    EditText pifu_qita;
    EditText pifu_beizhu;
    //肺心率
    RadioGroup group_fei_xinlv;
    RadioButton xinlv_qi;
    RadioButton xinlv_buqi;
    RadioButton xinlv_jueduibuqi;
    String feiXinLvStr="1";
    EditText fei_xinlv_qita;
    EditText fei_xinlv_beizhu;
    //杂音
    RadioGroup group_zayin;
    RadioButton zayin_no;
    RadioButton zayin_yes;
    String zayinStr="1";
    EditText zayin_qita;
    EditText zayin_beizhu;
    //压痛
    RadioGroup group_yatong;
    RadioButton yatong_no;
    RadioButton yatong_yes;
    String yatongStr="1";
    EditText yatong_qita;
    EditText yatong_beizhu;
    //包块
    RadioGroup group_baokuai;
    RadioButton baokuai_no;
    RadioButton baokuai_yes;
    String baokuaiStr="1";
    EditText baokuai_qita;
    EditText baokuai_beizhu;
    //肝大
    RadioGroup group_ganda;
    RadioButton ganda_no;
    RadioButton ganda_yes;
    String gandaStr="1";
    EditText ganda_qita;
    EditText ganda_beizhu;
    //脾大
    RadioGroup group_pida;
    RadioButton pida_no;
    RadioButton pida_yes;
    String pidaStr="1";
    EditText pida_qita;
    EditText pida_beizhu;
    //浊音
    RadioGroup group_zhuoyin;
    RadioButton zhuoyin_no;
    RadioButton zhuoyin_yes;
    String zhuoyinStr="1";
    EditText zhuoyin_qita;
    EditText zhuoyin_beizhu;










    private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");

    private int pos_doc = 0;

    // 患者签名
    private String strPatientSignPath = "";

    // 医生签名
    private String strDocSignPath = "";

    // 患者
    private final int REQUEST_CODE_PATIENT = 11;
    // 医生
    private final int REQUEST_CODE_DOCTOR = 12;

    boolean isSave=false;//是否保存

    private String str = UUID.randomUUID().toString();
    String uuid = str.substring(0, 8) + str.substring(9, 13) + str.substring(14, 18) + str.substring(19, 23) + str.substring(24, 30);
    List<String> xuetangList = new ArrayList<String>();


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_lvyue);
        userinfo = NovaApplication.getUserInfo();
        xuetangList.add("空腹血糖");
        xuetangList.add("餐后1小时血糖");
        xuetangList.add("餐后2小时血糖");
        xuetangList.add("随机血糖");
        findViews();
        setListeners();
        setData();
    }

    @Override
    public void findViews() {
        btn_back=findViewById(R.id.btn_back);
        title=findViewById(R.id.title);
        title.setText("履约服务记录表");
        btn_up=findViewById(R.id.btn_up);

        ed_date=findViewById(R.id.ed_date);
        lvyue_name=findViewById(R.id.lvyue_name);
        lvYue_age=findViewById(R.id.lvyue_age);

        lvyueHight=findViewById(R.id.lvyue_hight);
        lvyueWeight=findViewById(R.id.lvyue_weight);
        lvyueWeightBtn=findViewById(R.id.lvyue_btn_weight);
        lvyueTzzs=findViewById(R.id.lvyue_tzzs);
        lvyueHuxi=findViewById(R.id.lvyue_huxi);
        lvyueXinlv=findViewById(R.id.lvyue_xinlv);
        lvyueXinlvBtn=findViewById(R.id.lvyue_btn_xinlv);

        lvyueTiwen=findViewById(R.id.lvyue_tiwen);
        lvyueTiWenBtn=findViewById(R.id.lvyue_btn_tiwen);
        lvyueXueYaGao=findViewById(R.id.lvyue_xueya_gao);
        lvyueXueYaDi=findViewById(R.id.lvyue_xueya_di);
        lvyueXueYaBtn=findViewById(R.id.lvyue_btn_xueYa);
        lvyueXueTang=findViewById(R.id.lvyue_xuetang);
        xuetang_spinner=findViewById(R.id.xuetang_spinner);
        SpinnerAdapter spinnerAdapter=new SpinnerAdapter(LvYueJiLuActivity.this,xuetangList);
        xuetang_spinner.setAdapter(spinnerAdapter);
        lvyueXueTangBtn=findViewById(R.id.lvyue_btn_xueTang);
        lvyueJiBing=findViewById(R.id.lvyue_jibing);
        lvyueJiBing_beizhu=findViewById(R.id.jibing_beizhu);
        lvyueJkgl=findViewById(R.id.lvyue_jkgl);
        lvyuejkgy_beizhu=findViewById(R.id.jkgl_beizhu);
        lvyueZyqk=findViewById(R.id.lvyue_zyqk);
        lvyuezyqk_beizhu=findViewById(R.id.zhuyuan_beizhu);
        lvyueYongyao=findViewById(R.id.lvyue_yongyao);
        yongYao_beizhu=findViewById(R.id.yongyao_beizhu);

        lvyueZzqk=findViewById(R.id.lvyue_zzqk);
        zhuanzhen_beizhu=findViewById(R.id.zhuanzhen_beizhu);
        lvyuedocName=findViewById(R.id.lvyue_docname);
        lvyueDocImg=findViewById(R.id.img_doctorsign);
        lvyueDocBtn=findViewById(R.id.btn_doctorsign);
        lvyueHuanName=findViewById(R.id.lvyue_juming_name);
        lvyueHuanImg=findViewById(R.id.img_patientsign);
        lvyueHuanBtn=findViewById(R.id.btn_patientsign);
        lvyueBeiZhu=findViewById(R.id.lvyue_beizhu);
        docname_beizhu=findViewById(R.id.doc_beizhu);
        username_beizhu=findViewById(R.id.user_beizhu);

        beiZhu1=findViewById(R.id.lvyue_beizhu1);
        beiZhu2=findViewById(R.id.lvyue_beizhu2);
        beiZhu3=findViewById(R.id.lvyue_beizhu3);

        //口唇
        group_kouchun=findViewById(R.id.group_kouchun);
        kouchun_hongrun=findViewById(R.id.kouchun_hongrui);
        kouchun_cangbai=findViewById(R.id.kouchun_cangbai);
        kouchun_fangan=findViewById(R.id.kouchun_fagan);
        kouchun_qita=findViewById(R.id.kouchun_qita);
        kouchun_beizhu=findViewById(R.id.kouchun_beizhu);

        //齿列
        chilie_zhengchuang=findViewById(R.id.chilie_zhengchang);
        chilie_quechi=findViewById(R.id.chilie_quechi);
        chilie_yuchi=findViewById(R.id.chilie_yuchi);
        chilie_yichi=findViewById(R.id.chilie_yichi);
        chilie_qita=findViewById(R.id.chile_qita);
        chilie_beizhu=findViewById(R.id.chile_beizhu);
        //咽部
        yanbu_wuchongxue=findViewById(R.id.yanbu_wuchongxue);
        yanbu_chongxue=findViewById(R.id.yanbu_chongxue);
        yanbu_linba=findViewById(R.id.yanbu_zengsheng);
        yanbu_qita=findViewById(R.id.yanbu_qita);
        yanbu_beizhu=findViewById(R.id.yanbu_beizhu);
        //听力
        group_tingli=findViewById(R.id.group_tingli);
        tingli_yes=findViewById(R.id.tingli_yes);
        tingli_no=findViewById(R.id.tingli_no);
        tingli_qita=findViewById(R.id.tingli_qita);
        tingli_beizhu=findViewById(R.id.tingli_beizhu);
        //皮肤
        group_pifu=findViewById(R.id.group_pifu);
        pifu_zhengchang=findViewById(R.id.pifu_zhengchang);
        pifu_chaoshi=findViewById(R.id.pifu_chaoshi);
        pifu_cangbai=findViewById(R.id.pifu_cangbai);
        pifu_fagan=findViewById(R.id.pifu_fagan);
        pifu_huangran=findViewById(R.id.pifu_huangran);
        pifu_qita=findViewById(R.id.pifu_qita);
        pifu_beizhu=findViewById(R.id.pifu_beizhu);
        //肺心率
        group_fei_xinlv=findViewById(R.id.group_xinlv);
        xinlv_qi=findViewById(R.id.xinlv_qi);
        xinlv_buqi=findViewById(R.id.xinlv_buqi);
        xinlv_jueduibuqi=findViewById(R.id.xinlv_jueduibuqi);
        fei_xinlv_qita=findViewById(R.id.xinlv_qita);
        fei_xinlv_beizhu=findViewById(R.id.xinlv_beizhu);
        //杂音
        group_zayin=findViewById(R.id.group_zayin);
        zayin_no=findViewById(R.id.zayin_no);
        zayin_yes=findViewById(R.id.zayin_yes);
        zayin_qita=findViewById(R.id.zayin_qita);
        zayin_beizhu=findViewById(R.id.zayin_beizhu);
        //压痛
        group_yatong=findViewById(R.id.group_yatong);
        yatong_no=findViewById(R.id.yatong_no);
        yatong_yes=findViewById(R.id.yatong_yes);
        yatong_qita=findViewById(R.id.yatong_qita);
        yatong_beizhu=findViewById(R.id.yatong_beizhu);
        //包块
        group_baokuai=findViewById(R.id.group_baokuai);
        baokuai_no=findViewById(R.id.baokuai_no);
        baokuai_yes=findViewById(R.id.baokuai_yes);
        baokuai_qita=findViewById(R.id.baokuai_qita);
        baokuai_beizhu=findViewById(R.id.baokuai_beizhu);
        //肝大
        group_ganda=findViewById(R.id.group_ganda);
        ganda_no=findViewById(R.id.ganda_no);
        ganda_yes=findViewById(R.id.ganda_yes);
        ganda_qita=findViewById(R.id.ganda_qita);
        ganda_beizhu=findViewById(R.id.ganda_beizhu);
        //脾大
        group_pida=findViewById(R.id.group_pida);
        pida_no=findViewById(R.id.pida_no);
        pida_yes=findViewById(R.id.pida_yes);
        pida_qita=findViewById(R.id.pida_qita);
        pida_beizhu=findViewById(R.id.pida_beizhu);
        //浊音
        group_zhuoyin=findViewById(R.id.group_zhuoyin);
        zhuoyin_no=findViewById(R.id.zhuoyin_no);
        zhuoyin_yes=findViewById(R.id.zhuoyin_yes);
        zhuoyin_qita=findViewById(R.id.zhuoyin_qita);
        zhuoyin_beizhu=findViewById(R.id.zhuoyin_beizhu);








    }

    /**
     * 设置签名图片
     */
    @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
    private void initSignPhotoData(JTYSCustomerDoctorCont cont) {
//        List<JTYS_SignPictureData> pictures = NovaApplication.fdbmanger.findAllByWhere(JTYS_SignPictureData.class,
//                "CardNum = '" + userInfo.getIDCARD() + "'");
        List<JTYS_SignPictureData> pictures = NovaApplication.fdbmanger.findAllByWhere(JTYS_SignPictureData.class,
                "CardNum = '" + cont.getCardNum() + "'");


        for (JTYS_SignPictureData pic : pictures) {
            switch (pic.type()) {
                case "4":// 医生签名
                    setSign(pic.getPhotoPath(), lvyueDocImg);
                    break;
                case "5":// 患者签名
                    setSign(pic.getPhotoPath(), lvyueHuanImg);
                    break;

                default:
                    break;
            }
        }

    }
    SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddhhmmss");
    /**
     * 客户身份证号_签约时间_用户类型_创建时间时分秒_随机数.png
     * <p>
     * 370883198806046521_2017-12-07_1_20171207104138_8140.png
     *
     * @param type 1 医生 签名 2 患者签名 3 其他照片
     * @return
     * @author 鹿云龙
     * @date 2017年12月26日 上午10:13:28
     */
    private String getPhotoPath(String type) {
        if (type == null) {
            return null;
        }
        String str = "";
        File file = null;

        file = new File(Environment.getExternalStorageDirectory() + "/PublicHealth/LvyueSign/");
        str = Environment.getExternalStorageDirectory() + "/PublicHealth/LvyueSign/" + userinfo.getIDCARD() + "_"
                + ed_date.getText().toString() + "_" + type + "_" + sdf.format(new Date()) + "_"
                + (int) ((Math.random() * 9 + 1) * 1000) + ".png";

        if (!file.exists()) {
            file.mkdirs();
        }
        return str;
    }
    @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
    private void setSign(String imgPath, ImageView v) {
        // String result = "";

        if (!TextUtils.isEmpty(imgPath)) {
            Log.e("***", "照片src：" + imgPath);
            File file = new File(imgPath);
            if (file.exists()) {
                // v.setbacImageBitmap(ImageTools.readBitmapAutoSize(imgPath));
                v.setVisibility(View.VISIBLE);
                v.setBackground(new BitmapDrawable(null, ImageTools.readBitmapAutoSize(imgPath)));
            } else {
                v.setImageBitmap(null);
            }
        }
    }


    /**
     * 初始化赋值
     */
    public void setData(){
        lvyue_name.setText(userinfo.getCUSTOMERNAME());
        int age = GlobalConts.getAge(userinfo.getBIRTHDAY());
        if (age != -1) {
            lvYue_age.setText(String.valueOf(age) + "岁");
        } else {
            lvYue_age.setText("");
        }

       ed_date.setText(GlobalConts.dateFormat.format(new Date()));
        lvyueHuanName.setText(userinfo.getCUSTOMERNAME());
        bindSpinnerQyDocList(NovaApplication.getDoctorList());
        List<SBCL_DATA> twList = NovaApplication.fdbmanger.findAllByWhere(SBCL_DATA.class, "IDCARD = '" + userinfo.getIDCARD()
                + "' and " + "(CL_TYPE='体温' or CL_TYPE='表面温度')" + " and " + "CL_TIME like '" + dateFormat.format(new Date()) + "%'");
        List<SBCL_DATA> mlList = NovaApplication.fdbmanger.findAllByWhere(SBCL_DATA.class, "IDCARD = '" + userinfo.getIDCARD()
                + "' and " + "CL_TYPE='脉率'" + " and " + "CL_TIME like '" + dateFormat.format(new Date()) + "%'");
        List<SBCL_DATA> gyList = NovaApplication.fdbmanger.findAllByWhere(SBCL_DATA.class, "IDCARD = '" + userinfo.getIDCARD()
                + "' and " + "CL_TYPE='高压'" + " and " + "CL_TIME like '" + dateFormat.format(new Date()) + "%'");
        List<SBCL_DATA> dyList = NovaApplication.fdbmanger.findAllByWhere(SBCL_DATA.class, "IDCARD = '" + userinfo.getIDCARD()
                + "' and " + "CL_TYPE='低压'" + " and " + "CL_TIME like '" + dateFormat.format(new Date()) + "%'");
        List<SBCL_DATA> tzList = NovaApplication.fdbmanger.findAllByWhere(SBCL_DATA.class, "IDCARD = '" + userinfo.getIDCARD()
                        + "' and " + "CL_TYPE='体重'" + " and " + "CL_TIME like '" + dateFormat.format(new Date()) + "%'",
                "CL_TIME desc");

        List<SBCL_DATA> xTList = NovaApplication.fdbmanger.findAllByWhere(SBCL_DATA.class, "IDCARD = '" + userinfo.getIDCARD()
                + "' and " + "CL_TYPE='血糖'" + " and " + "CL_TIME like '" + dateFormat.format(new Date()) + "%'");
        if(twList.size()>0){
            lvyueTiwen.setText(twList.get(twList.size() - 1).getCL_VALUE().split("℃")[0]);
        }
        if(tzList.size()>0){
            lvyueWeight.setText(tzList.get(0).getCL_VALUE().split("Kg")[0]);
        }

        if(mlList.size()>0){
            String value = mlList.get(mlList.size() - 1).getCL_VALUE();
            if (value.contains("次/分")) {
                lvyueXinlv.setText(value.split("次/分")[0]);
            } else if (value.contains("bpm")) {
                lvyueXinlv.setText(value.split("bpm")[0]);
            }
        }

        if (gyList.size() > 0) {
            lvyueXueYaGao.setText(gyList.get(gyList.size() - 1).getCL_VALUE().split("mmHg")[0]);
        }
        if (dyList.size() > 0) {
            lvyueXueYaDi.setText(dyList.get(dyList.size() - 1).getCL_VALUE().split("mmHg")[0]);
        }

        if(xTList.size()>0){
            lvyueXueTang.setText(xTList.get(xTList.size()-1).getCL_VALUE().split("mmol/L")[0]);
        }


    }
    public void bindSpinnerQyDocList(List<BD_ORGANIZE_EMPLOYEE> bds) {
        // 判断当前城市在数组中的位置并显示
        QYDoctersAdapter adapter_bsc = new QYDoctersAdapter(getApplicationContext(), bds);
        // adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        lvyuedocName.setAdapter(adapter_bsc);
    }

    @Override
    public void setListeners() {
        btn_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        lvyueWeightBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(LvYueJiLuActivity.this, ExamHistoryActivity.class);
                intent.putExtra("flag", BluetoothConstant.TIZHONG_TYPENAME);
                startActivityForResult(intent, GlobalConts.RequestTizhong);
            }
        });
        lvyueXinlvBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(LvYueJiLuActivity.this, ExamHistoryActivity.class);
                intent.putExtra("flag", "心率");
                startActivityForResult(intent, GlobalConts.RequestMaiLv);
            }
        });
        lvyueTiWenBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(LvYueJiLuActivity.this, ExamHistoryActivity.class);
                intent.putExtra("flag", BluetoothConstant.TIWEN_TYPENAME);
                startActivityForResult(intent, GlobalConts.RequestTiwen);
            }
        });
        lvyueXueYaBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(LvYueJiLuActivity.this, ExamHistoryActivity.class);
                intent.putExtra("flag", BluetoothConstant.XUEYA_TYPENAME);
                startActivityForResult(intent, GlobalConts.RequestXueya);
            }
        });
        lvyueXueTangBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(LvYueJiLuActivity.this, ExamHistoryActivity.class);
                intent.putExtra("flag", BluetoothConstant.XUETANG_TYPENAME);
                startActivityForResult(intent, GlobalConts.RequestXuetang);
            }
        });

        xuetang_spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                xuetangType=position+1+"";
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });
        //口唇
        group_kouchun.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if(kouchun_hongrun.getId()==checkedId){
                    kouchunStr="1";
                }else if(kouchun_cangbai.getId()==checkedId){
                    kouchunStr="2";
                }else if(kouchun_fangan.getId()==checkedId){
                    kouchunStr="3";
                }
            }
        });
        //齿列
        chilie_zhengchuang.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked){
                    chilie_quechi.setChecked(false);
                    chilie_yuchi.setChecked(false);
                    chilie_yichi.setChecked(false);

                }
            }
        });
        chilie_quechi.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked){
                    chilie_zhengchuang.setChecked(false);
                }
            }
        });
        chilie_yichi.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked){
                    chilie_zhengchuang.setChecked(false);
                }
            }
        });
        chilie_yuchi.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked){
                    chilie_zhengchuang.setChecked(false);
                }
            }
        });
        //咽部
        yanbu_wuchongxue.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked){
                    yanbu_chongxue.setChecked(false);
                    yanbu_linba.setChecked(false);
                }
            }
        });
        yanbu_chongxue.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked){
                    yanbu_wuchongxue.setChecked(false);
                }
            }
        });
        yanbu_linba.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked){
                    yanbu_wuchongxue.setChecked(false);
                }
            }
        });
        //听力
        group_tingli.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if(tingli_yes.getId()==checkedId){
                    tingliStr="1";
                }else if(tingli_no.getId()==checkedId){
                    tingliStr="2";
                }
            }
        });

        //皮肤
        group_pifu.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if(pifu_zhengchang.getId()==checkedId){
                    pifuStr="1";
                }else if(pifu_chaoshi.getId()==checkedId){
                    pifuStr="2";
                }else if(pifu_cangbai.getId()==checkedId){
                    pifuStr="3";
                }else if(pifu_fagan.getId()==checkedId){
                    pifuStr="4";
                }else if(pifu_huangran.getId()==checkedId){
                    pifuStr="5";
                }
            }
        });
        //肺心率
        group_fei_xinlv.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if(xinlv_qi.getId()==checkedId){
                    feiXinLvStr="1";
                }else if(xinlv_buqi.getId()==checkedId){
                    feiXinLvStr="2";
                }else if(xinlv_jueduibuqi.getId()==checkedId){
                    feiXinLvStr="3";
                }
            }
        });
        //杂音
        group_zayin.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if(zayin_no.getId()==checkedId){
                    zayinStr="1";
                }else if(zayin_yes.getId()==checkedId){
                    zayinStr="2";
                }
            }
        });
        //压痛
        group_yatong.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if(yatong_no.getId()==checkedId){
                    yatongStr="1";
                }else if(yatong_yes.getId()==checkedId){
                    yatongStr="2";
                }
            }
        });
        //包块
        group_baokuai.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if(baokuai_no.getId()==checkedId){
                    baokuaiStr="1";
                }else if(baokuai_yes.getId()==checkedId){
                    baokuaiStr="2";
                }
            }
        });
        //肝大
        group_ganda.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if(ganda_no.getId()==checkedId){
                    gandaStr="1";
                }else if(ganda_yes.getId()==checkedId){
                    gandaStr="2";
                }
            }
        });
       //脾大
        group_pida.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if(pida_no.getId()==checkedId){
                    pidaStr="1";

                }else if(pida_yes.getId()==checkedId){
                    pidaStr="2";
                }
            }
        });
        //浊音
        group_zhuoyin.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if(zhuoyin_no.getId()==checkedId){
                    zhuoyinStr="1";
                }else if(zhuoyin_yes.getId()==checkedId){
                    zhuoyinStr="2";
                }
            }
        });



        lvyuedocName.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                pos_doc = position;
                setSpinnerPos(position);
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });
        lvyueHuanBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 患者签名btn
                if (userinfo != null) {


                    if ("重签".equals(lvyueHuanBtn.getText())) {
                        judgeFileIsExistsAndDelete(strPatientSignPath);
                    }

                    Intent intent = new Intent(LvYueJiLuActivity.this, QianMingActivity.class);
                    // //命名规则： 身份证号_签约时间_用户类型_创建时间时分秒_随机数.png[用户类型： 1 医生 2 患者 3
                    // 其他图片]
                    intent.putExtra(QianMingActivity.SIGNNAME_HEAD, getPhotoPath("5"));
                    startActivityForResult(intent, REQUEST_CODE_PATIENT);
                } else {
                    showTextDialog("没有获取到用户数据");
                }
            }
        });

        lvyueDocBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 医生签名btn
                if (userinfo != null) {


                    if ("重签".equals(lvyueDocBtn.getText())) {
                        judgeFileIsExistsAndDelete(strDocSignPath);
                    }

                    Intent intent = new Intent(LvYueJiLuActivity.this, QianMingActivity.class);
                    // //命名规则： 身份证号_签约时间_用户类型_创建时间时分秒_随机数.png[用户类型： 1 医生 2 患者 3
                    // 其他图片]
                    intent.putExtra(QianMingActivity.SIGNNAME_HEAD, getPhotoPath("4"));
                    startActivityForResult(intent, REQUEST_CODE_DOCTOR);
                } else {
                    showTextDialog("没有获取到用户数据");
                }
            }
        });
        changeBMI(lvyueHight,lvyueWeight,lvyueTzzs);
        btn_up.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(isSave){
                    showTextDialog("该记录已保存过");
                    return;
                }
                List<LvYueFuWuBean> lvYueFuWuBeans=NovaApplication.fdbmanger.findAllByWhere(LvYueFuWuBean.class,"cardNum='"+ userinfo.getIDCARD()+"' and lvyueDate='"+ ed_date.getText().toString()+"'");
                if(lvYueFuWuBeans.size()>0){
                    showTextDialog("相同服务时间只能添加一条履约记录");
                    return;
                }
                if(TextUtils.isEmpty(lvyueHight.getText())){
                    showTextDialog("请输入身高");
                    return;
                }
                if(TextUtils.isEmpty(lvyueWeight.getText())){
                    showTextDialog("请输入体重");
                    return;
                }
                if(TextUtils.isEmpty(lvyueHuxi.getText())){
                    showTextDialog("请输入呼吸频率");
                    return;
                }
                if(TextUtils.isEmpty(lvyueXinlv.getText())){
                    showTextDialog("请输入心率");
                    return;
                }
                if(TextUtils.isEmpty(lvyueTiwen.getText())){
                    showTextDialog("请输入体温");
                    return;
                }
                if(TextUtils.isEmpty(lvyueXueYaGao.getText())||TextUtils.isEmpty(lvyueXueYaDi.getText())){
                    showTextDialog("请输入血压");
                    return;
                }
//                if(TextUtils.isEmpty(lvyueXueTang.getText())){
//                    showTextDialog("请输入血糖");
//                    return;
//                }

                if(TextUtils.isEmpty(strDocSignPath)){
                    showTextDialog("请家庭医生签名");
                    return;
                }
                if(TextUtils.isEmpty(strPatientSignPath)){
                    showTextDialog("请签约人签名");
                    return;
                }

                LvYueFuWuBean lvyue=new LvYueFuWuBean();
                lvyue.setId(uuid.substring(0,18));
                if(!TextUtils.isEmpty(userinfo.getARCHIVEID())){
                    lvyue.setPersonalId(userinfo.getARCHIVEID());
                }
                lvyue.setSignatory(userinfo.getCUSTOMERNAME());
                lvyue.setCreateOrg(userinfo.getCREATEORG());
                lvyue.setCreater(userinfo.getCREATER());
                lvyue.setCreatedate(GlobalConts.datetimeFormat.format(new Date()));

                lvyue.setCardNum(userinfo.getIDCARD());
                lvyue.setName(userinfo.getCUSTOMERNAME());
                lvyue.setAge(lvYue_age.getText().toString());
                lvyue.setLvyueDate(ed_date.getText().toString());
                lvyue.setHight(lvyueHight.getText().toString());
                lvyue.setWeight(lvyueWeight.getText().toString());
                lvyue.setTzzs(lvyueTzzs.getText().toString());
                lvyue.setHuxi(lvyueHuxi.getText().toString());
                lvyue.setXinlv(lvyueXinlv.getText().toString());
                lvyue.setTiWen(lvyueTiwen.getText().toString());
                lvyue.setXueyaGao(lvyueXueYaGao.getText().toString());
                lvyue.setXueyaDi(lvyueXueYaDi.getText().toString());
                if(!TextUtils.isEmpty(lvyueXueTang.getText())){
                    lvyue.setXueTang(lvyueXueTang.getText().toString());
                    lvyue.setXueTangType(xuetangType);
                }

                if(TextUtils.isEmpty(beiZhu1.getText())){
                    lvyue.setBeiZhu1("无");
                }else{
                    lvyue.setBeiZhu1(beiZhu1.getText().toString());
                }
                if(TextUtils.isEmpty(beiZhu2.getText())){
                    lvyue.setBeiZhu2("无");
                }else{
                    lvyue.setBeiZhu2(beiZhu2.getText().toString());
                }
                if(TextUtils.isEmpty(beiZhu3.getText())){
                    lvyue.setBeiZhu3("无");
                }else{
                    lvyue.setBeiZhu3(beiZhu3.getText().toString());
                }

                lvyue.setKouchun(kouchunStr);
                if(TextUtils.isEmpty(kouchun_qita.getText())){
                    lvyue.setKouchun_qita("无");
                }else{
                    lvyue.setKouchun_qita(kouchun_qita.getText().toString());
                }
                if(TextUtils.isEmpty(kouchun_beizhu.getText())){
                    lvyue.setKouchun_beizhu("无");
                }else{
                    lvyue.setKouchun_beizhu(kouchun_beizhu.getText().toString());
                }
                if(chilie_zhengchuang.isChecked()){
                    chilieStr="1";
                }
                if(chilie_quechi.isChecked()){
                   if("1".equals(chilieStr)){
                       chilieStr="2";
                   }else{
                       chilieStr=chilieStr+",2";
                   }
                }
                if(chilie_yuchi.isChecked()){
                    if("1".equals(chilieStr)){
                        chilieStr="3";
                    }else{
                        chilieStr=chilieStr+",3";
                    }
                }
                if(chilie_yichi.isChecked()){
                    if("1".equals(chilieStr)){
                        chilieStr="4";
                    }else{
                        chilieStr=chilieStr+",4";
                    }
                }
                lvyue.setChilie(chilieStr);
                if(TextUtils.isEmpty(chilie_qita.getText())){
                    lvyue.setChilie_qita("无");
                }else{
                    lvyue.setChilie_qita(chilie_qita.getText().toString());
                }
                if(TextUtils.isEmpty(chilie_beizhu.getText())){
                    lvyue.setChilie_beizhu("无");
                }else{
                    lvyue.setChilie_beizhu(chilie_beizhu.getText().toString());
                }
                if(yanbu_wuchongxue.isChecked()){
                    yanbuStr="1";
                }
                if(yanbu_chongxue.isChecked()){
                    if("1".equals(yanbuStr)){
                        yanbuStr="2";
                    }else{
                        yanbuStr=yanbuStr+",2";
                    }
                }
                if(yanbu_chongxue.isChecked()){
                    if("1".equals(yanbuStr)){
                        yanbuStr="2";
                    }else{
                        yanbuStr=yanbuStr+",2";
                    }
                }
                if(yanbu_linba.isChecked()){
                    if("1".equals(yanbuStr)){
                        yanbuStr="3";
                    }else{
                        yanbuStr=yanbuStr+",3";
                    }
                }

                lvyue.setYanbu(yanbuStr);
                if(TextUtils.isEmpty(yanbu_qita.getText())){
                    lvyue.setYanbu_qita("无");
                }else{
                    lvyue.setYanbu_qita(yanbu_qita.getText().toString());
                }
                if(TextUtils.isEmpty(yanbu_beizhu.getText())){
                    lvyue.setYanbu_beizhu("无");
                }else{
                    lvyue.setYanbu_beizhu(yanbu_beizhu.getText().toString());
                }

                lvyue.setTingli(tingliStr);
                if(TextUtils.isEmpty(tingli_qita.getText())){
                    lvyue.setTingli_qita("无");
                }else{
                    lvyue.setTingli_qita(tingli_qita.getText().toString());
                }
                if(TextUtils.isEmpty(tingli_beizhu.getText())){
                    lvyue.setTingli_beizhu("无");
                }else{
                    lvyue.setTingli_beizhu(tingli_beizhu.getText().toString());
                }
                lvyue.setPifu(pifuStr);
                if(TextUtils.isEmpty(pifu_qita.getText())){
                    lvyue.setPifu_qita("无");
                }else{
                    lvyue.setPifu_qita(pifu_qita.getText().toString());
                }
                if(TextUtils.isEmpty(pifu_beizhu.getText())){
                    lvyue.setPifu_beizhu("无");
                }else{
                    lvyue.setPifu_beizhu(pifu_beizhu.getText().toString());
                }

                lvyue.setFei_xinlv(feiXinLvStr);

                if(TextUtils.isEmpty(fei_xinlv_qita.getText())){
                    lvyue.setFei_xinlv_qita("无");
                }else{
                    lvyue.setFei_xinlv_qita(fei_xinlv_qita.getText().toString());
                }
                if(TextUtils.isEmpty(fei_xinlv_beizhu.getText())){
                    lvyue.setFei_xinlv_beizhu("无");
                }else{
                    lvyue.setFei_xinlv_beizhu(fei_xinlv_beizhu.getText().toString());
                }

                lvyue.setZayin(zayinStr);
                if(TextUtils.isEmpty(zayin_qita.getText())){
                    lvyue.setZayin_qita("无");
                }else{
                    lvyue.setZayin_qita(zayin_qita.getText().toString());
                }
                if(TextUtils.isEmpty(zayin_beizhu.getText())){
                    lvyue.setZayin_beizhu("无");
                }else{
                    lvyue.setZayin_beizhu(zayin_beizhu.getText().toString());
                }

                lvyue.setYatong(yatongStr);

                if(TextUtils.isEmpty(yatong_qita.getText())){
                    lvyue.setYatong_qita("无");
                }else{
                    lvyue.setYatong_qita(yatong_qita.getText().toString());
                }
                if(TextUtils.isEmpty(yatong_beizhu.getText())){
                    lvyue.setYatong_beizhu("无");
                }else{
                    lvyue.setYatong_beizhu(yatong_beizhu.getText().toString());
                }
                lvyue.setBaokuai(baokuaiStr);
                if(TextUtils.isEmpty(baokuai_qita.getText())){
                    lvyue.setBaokuai_qita("无");
                }else{
                    lvyue.setBaokuai_qita(baokuai_qita.getText().toString());
                }
                if(TextUtils.isEmpty(baokuai_beizhu.getText())){
                    lvyue.setBaokuai_beizhu("无");
                }else{
                    lvyue.setBaokuai_beizhu(baokuai_beizhu.getText().toString());
                }
                lvyue.setGanda(gandaStr);
                if(TextUtils.isEmpty(ganda_qita.getText())){
                    lvyue.setGanda_qita("无");
                }else{
                    lvyue.setGanda_qita(ganda_qita.getText().toString());
                }
                if(TextUtils.isEmpty(ganda_beizhu.getText())){
                    lvyue.setGanda_beizhu("无");
                }else{
                    lvyue.setGanda_beizhu(ganda_beizhu.getText().toString());
                }
                lvyue.setPida(pidaStr);
                if(TextUtils.isEmpty(pida_qita.getText())){
                    lvyue.setPida_qita("无");
                }else{
                    lvyue.setPida_qita(pida_qita.getText().toString());
                }
                if(TextUtils.isEmpty(pida_beizhu.getText())){
                    lvyue.setPida_beizhu("无");
                }else{
                    lvyue.setPida_beizhu(pida_beizhu.getText().toString());
                }
                lvyue.setZhuoyin(zhuoyinStr);
                if(TextUtils.isEmpty(zhuoyin_qita.getText())){
                    lvyue.setZhuoyin_qita("无");
                }else{
                    lvyue.setZhuoyin_qita(zhuoyin_qita.getText().toString());
                }
                if(TextUtils.isEmpty(zhuoyin_beizhu.getText())){
                    lvyue.setZhuoyin_beizhu("无");
                }else{
                    lvyue.setZhuoyin_beizhu(zhuoyin_beizhu.getText().toString());
                }

                if(TextUtils.isEmpty(lvyueJiBing.getText())){
                    lvyue.setJiBing("无");
                }else{
                    lvyue.setJiBing(lvyueJiBing.getText().toString());
                }
                if(TextUtils.isEmpty(lvyueJiBing_beizhu.getText())){
                    lvyue.setJibing_beizhu("无");
                }else{
                    lvyue.setJibing_beizhu(lvyueJiBing_beizhu.getText().toString());
                }
                if(TextUtils.isEmpty(lvyueJkgl.getText())){
                    lvyue.setJkgl("无");
                }else{
                    lvyue.setJkgl(lvyueJkgl.getText().toString());
                }
                if(TextUtils.isEmpty(lvyuejkgy_beizhu.getText())){
                    lvyue.setJkgy_beizhu("无");
                }else{
                    lvyue.setJkgy_beizhu(lvyuejkgy_beizhu.getText().toString());
                }

                if(TextUtils.isEmpty(lvyueZyqk.getText())){
                    lvyue.setZyqk("无");
                }else{
                    lvyue.setZyqk(lvyueZyqk.getText().toString());
                }
                if(TextUtils.isEmpty(lvyuezyqk_beizhu.getText())){
                    lvyue.setZyqk_beizhu("无");
                }else{
                    lvyue.setZyqk_beizhu(lvyuezyqk_beizhu.getText().toString());
                }
                if(TextUtils.isEmpty(lvyueYongyao.getText())){
                    lvyue.setYongyao("无");
                }else{
                    lvyue.setYongyao(lvyueYongyao.getText().toString());
                }
                if(TextUtils.isEmpty(yongYao_beizhu.getText())){
                    lvyue.setYongyao_beizhu("无");
                }else{
                    lvyue.setYongyao_beizhu(yongYao_beizhu.getText().toString());
                }

                if(TextUtils.isEmpty(lvyueZzqk.getText())){
                    lvyue.setZzqk("无");
                }else{
                    lvyue.setZzqk(lvyueZzqk.getText().toString());
                }
                if(TextUtils.isEmpty(zhuanzhen_beizhu.getText())){
                    lvyue.setZzqk_beizhu("无");
                }else{
                    lvyue.setZzqk_beizhu(zhuanzhen_beizhu.getText().toString());
                }
                if(TextUtils.isEmpty(docname_beizhu.getText())){
                    lvyue.setDocName_beizhu("无");
                }else{
                    lvyue.setDocName_beizhu(docname_beizhu.getText().toString());
                }
                if(TextUtils.isEmpty(username_beizhu.getText())){
                    lvyue.setUserName_beizhu("无");
                }else{
                    lvyue.setUserName_beizhu(username_beizhu.getText().toString());
                }
                lvyue.setDocName(NovaApplication.getDoctorList().get(pos_doc).getNAME());
                lvyue.setDocQianMingStr(strDocSignPath);
                lvyue.setHuanQianMingStr(strPatientSignPath);
                lvyue.setIs_Update("Y");
                if(TextUtils.isEmpty(lvyueBeiZhu.getText())){
                    lvyue.setBeiZhu("无");
                }else{
                    lvyue.setBeiZhu(lvyueBeiZhu.getText().toString());
                }
                if(NovaApplication.dbManger.isExistLvyue()){
                    if(NovaApplication.dbManger.checkColumnExists("LvYueFuWuBean","pida")){
                        NovaApplication.fdbmanger.save(lvyue);
                    }else{
                        NovaApplication.dbManger.addColumnByBySQL("LvYueFuWuBean", "beiZhu1");
                        NovaApplication.dbManger.addColumnByBySQL("LvYueFuWuBean", "beiZhu2");
                        NovaApplication.dbManger.addColumnByBySQL("LvYueFuWuBean", "beiZhu3");
                        NovaApplication.dbManger.addColumnByBySQL("LvYueFuWuBean", "kouchun");
                        NovaApplication.dbManger.addColumnByBySQL("LvYueFuWuBean", "kouchun_qita");
                        NovaApplication.dbManger.addColumnByBySQL("LvYueFuWuBean", "kouchun_beizhu");
                        NovaApplication.dbManger.addColumnByBySQL("LvYueFuWuBean", "chilie");
                        NovaApplication.dbManger.addColumnByBySQL("LvYueFuWuBean", "chilie_qita");
                        NovaApplication.dbManger.addColumnByBySQL("LvYueFuWuBean", "chilie_beizhu");
                        NovaApplication.dbManger.addColumnByBySQL("LvYueFuWuBean", "yanbu");
                        NovaApplication.dbManger.addColumnByBySQL("LvYueFuWuBean", "yanbu_qita");
                        NovaApplication.dbManger.addColumnByBySQL("LvYueFuWuBean", "yanbu_beizhu");
                        NovaApplication.dbManger.addColumnByBySQL("LvYueFuWuBean", "tingli");
                        NovaApplication.dbManger.addColumnByBySQL("LvYueFuWuBean", "tingli_qita");
                        NovaApplication.dbManger.addColumnByBySQL("LvYueFuWuBean", "tingli_beizhu");
                        NovaApplication.dbManger.addColumnByBySQL("LvYueFuWuBean", "pifu");
                        NovaApplication.dbManger.addColumnByBySQL("LvYueFuWuBean", "pifu_qita");
                        NovaApplication.dbManger.addColumnByBySQL("LvYueFuWuBean", "pifu_beizhu");
                        NovaApplication.dbManger.addColumnByBySQL("LvYueFuWuBean", "fei_xinlv");
                        NovaApplication.dbManger.addColumnByBySQL("LvYueFuWuBean", "fei_xinlv_qita");
                        NovaApplication.dbManger.addColumnByBySQL("LvYueFuWuBean", "fei_xinlv_beizhu");
                        NovaApplication.dbManger.addColumnByBySQL("LvYueFuWuBean", "zayin");
                        NovaApplication.dbManger.addColumnByBySQL("LvYueFuWuBean", "zayin_qita");
                        NovaApplication.dbManger.addColumnByBySQL("LvYueFuWuBean", "zayin_beizhu");
                        NovaApplication.dbManger.addColumnByBySQL("LvYueFuWuBean", "yatong");
                        NovaApplication.dbManger.addColumnByBySQL("LvYueFuWuBean", "yatong_qita");
                        NovaApplication.dbManger.addColumnByBySQL("LvYueFuWuBean", "yatong_beizhu");
                        NovaApplication.dbManger.addColumnByBySQL("LvYueFuWuBean", "baokuai");
                        NovaApplication.dbManger.addColumnByBySQL("LvYueFuWuBean", "baokuai_qita");
                        NovaApplication.dbManger.addColumnByBySQL("LvYueFuWuBean", "baokuai_beizhu");
                        NovaApplication.dbManger.addColumnByBySQL("LvYueFuWuBean", "ganda");
                        NovaApplication.dbManger.addColumnByBySQL("LvYueFuWuBean", "ganda_qita");
                        NovaApplication.dbManger.addColumnByBySQL("LvYueFuWuBean", "ganda_beizhu");
                        NovaApplication.dbManger.addColumnByBySQL("LvYueFuWuBean", "pida");
                        NovaApplication.dbManger.addColumnByBySQL("LvYueFuWuBean", "pida_qita");
                        NovaApplication.dbManger.addColumnByBySQL("LvYueFuWuBean", "pida_beizhu");
                        NovaApplication.dbManger.addColumnByBySQL("LvYueFuWuBean", "zhuoyin");
                        NovaApplication.dbManger.addColumnByBySQL("LvYueFuWuBean", "zhuoyin_qita");
                        NovaApplication.dbManger.addColumnByBySQL("LvYueFuWuBean", "zhuoyin_beizhu");
                        NovaApplication.dbManger.addColumnByBySQL("LvYueFuWuBean", "jiBing");
                        NovaApplication.dbManger.addColumnByBySQL("LvYueFuWuBean", "jibing_beizhu");
                        NovaApplication.dbManger.addColumnByBySQL("LvYueFuWuBean", "jkgy_beizhu");
                        NovaApplication.dbManger.addColumnByBySQL("LvYueFuWuBean", "zyqk_beizhu");
                        NovaApplication.dbManger.addColumnByBySQL("LvYueFuWuBean", "yongyao");
                        NovaApplication.dbManger.addColumnByBySQL("LvYueFuWuBean", "yongyao_beizhu");
                        NovaApplication.dbManger.addColumnByBySQL("LvYueFuWuBean", "zzqk_beizhu");
                        NovaApplication.dbManger.addColumnByBySQL("LvYueFuWuBean", "docName_beizhu");
                        NovaApplication.dbManger.addColumnByBySQL("LvYueFuWuBean", "userName_beizhu");
                        NovaApplication.dbManger.addColumnByBySQL("LvYueFuWuBean", "xueTangType");
                        NovaApplication.dbManger.addColumnByBySQL("LvYueFuWuBean","is_Update");
                        NovaApplication.dbManger.addColumnByBySQL("LvYueFuWuBean","personalId");
                        NovaApplication.dbManger.addColumnByBySQL("LvYueFuWuBean","signatory");
                        NovaApplication.dbManger.addColumnByBySQL("LvYueFuWuBean","createOrg");
                        NovaApplication.dbManger.addColumnByBySQL("LvYueFuWuBean","creater");
                        NovaApplication.dbManger.addColumnByBySQL("LvYueFuWuBean","createdate");


                        NovaApplication.fdbmanger.save(lvyue);
                    }
                }else{
                    NovaApplication.fdbmanger.save(lvyue);
                }


                isSave=true;

                showTextDialog("保存成功");

                finish();

            }
        });
    }

    /**
     * 判断该路径下文件是否存在，存在就删除
     *
     * @param path
     */
    private void judgeFileIsExistsAndDelete(String path) {
        if (!TextUtils.isEmpty(path)) {
            File file = new File(path);
            if (file.exists()) {
                file.delete();
            }
        }
    }

    /**
     * Spinner下拉
     *
     * @param pos
     * @author 王婷婷
     * @date 2017年4月26日 下午6:28:42
     */
    private void setSpinnerPos(int pos) {
//        String user_mobile = NovaApplication.getDoctorList().get(pos).getMOBILE();
//        if (TextUtils.isEmpty(user_mobile)) {
//            doc_phone_edit.setText("");
//        } else {
//            doc_phone_edit.setText(user_mobile);
//        }

        try {
            Field field = AdapterView.class.getDeclaredField("mOldSelectedPosition");
            field.setAccessible(true); // 设置mOldSelectedPosition可访问
            field.setInt(lvyuedocName, AdapterView.INVALID_POSITION); // 设置mOldSelectedPosition的值
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    /**
     * 身高或者体重改变时，BMI的值随之发生改变
     **/
    private void changeBMI(final EditText etHeight, final EditText etWeight, final EditText etBMI) {
        etHeight.addTextChangedListener(new TextWatcher() {

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                if (!TextUtils.isEmpty(etWeight.getText().toString())) {
                    setBMI(etHeight, etWeight, etBMI);
                }else{
                    etBMI.setText("");
                }

                if (TextUtils.isEmpty(s.toString())) {
                    etBMI.setText("");
                }

            }

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });

        etWeight.addTextChangedListener(new TextWatcher() {

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                if (!TextUtils.isEmpty(etHeight.getText().toString())) {
                    setBMI(etHeight, etWeight, etBMI);
                }else{
                    etBMI.setText("");
                }
                if (TextUtils.isEmpty(s.toString())) {
                    etBMI.setText("");
                }
            }

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                // TODO Auto-generated method stub

            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
    }
    /**
     * 设置BMI
     *
     * @author 王婷婷
     * @date 2017年4月5日 上午10:48:51
     */
    private void setBMI(EditText etHeight, EditText etWeight, EditText etBMI) {
        try {
            if (TextUtils.isEmpty(etHeight.getText().toString()) || TextUtils.isEmpty(etHeight.getText().toString())) {
                etBMI.setText("");
                return;
            }

            double dh = Double.parseDouble(etHeight.getText().toString()) / 100;
            double dw = Double.parseDouble(etWeight.getText().toString());

            java.text.DecimalFormat df = new java.text.DecimalFormat("#.00");

            etBMI.setText(df.format(GlobalConts.getBMI(dh, dw)) + "");
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        // TODO Auto-generated method stub
        super.onActivityResult(requestCode, resultCode, data);

        if (requestCode == GlobalConts.RequestXueya && resultCode == ExamHistoryActivity.ResultXueya) {
            lvyueXueYaGao.setText(data.getStringExtra("高压"));
            lvyueXueYaDi.setText(data.getStringExtra("低压"));

        } else if (requestCode == GlobalConts.RequestTizhong && resultCode == ExamHistoryActivity.ResultTizhong) {
            lvyueWeight.setText(data.getStringExtra("value"));
        }else if (requestCode == GlobalConts.RequestMaiLv && resultCode == com.novabluetooth.views.ExamHistoryActivity.ResultMaiLv) {
            Log.w("eeeeeeeee", data.getStringExtra("value"));
            lvyueXinlv.setText(data.getStringExtra("value"));
        }else if(requestCode == GlobalConts.RequestTiwen && resultCode == ExamHistoryActivity.ResultTiwen){
            Log.w("eeeeeeeee", data.getStringExtra("value"));
            lvyueTiwen.setText(data.getStringExtra("value"));
        }else if(requestCode == GlobalConts.RequestXuetang && resultCode == ExamHistoryActivity.ResultXuetang){
            Log.w("eeeeeeeee", data.getStringExtra("value"));
            lvyueXueTang.setText(data.getStringExtra("value"));
        }

        Log.e("*****", "结果返回码：" + requestCode + "\n" + resultCode);
        if (resultCode == RESULT_OK) {
            switch (requestCode) {
                case REQUEST_CODE_PATIENT:
                    if (data.getExtras().containsKey("filePath")) {
                        strPatientSignPath = data.getExtras().getString("filePath");
                        setSign(strPatientSignPath, lvyueHuanImg);
                        lvyueHuanBtn.setText("重签");
                    }
                    break;
                case REQUEST_CODE_DOCTOR:
                    if (data.getExtras().containsKey("filePath")) {
                        lvyueDocBtn.setText("重签");
                        strDocSignPath = data.getExtras().getString("filePath");
                        setSign(strDocSignPath, lvyueDocImg);
                    }
                    break;


                default:
                    break;
            }
        }
    }



   /* *//**
     * 保存图片信息所有的
     *
     * @author 王婷婷
     * @date 2017年12月7日 下午3:36:59
     *//*
    private void saveImgData() {
        Log.e("保存图片",strPatientSignPath+"***"+strDocSignPath);
        // 保存签名图片
        if (TextUtils.isEmpty(strPatientSignPath)) {
        } else {
            /// storage/emulated/0/PublicHealth/Sign/370883198806046521_2017-12-07_1__20171207161645_8987.png
            String[] strs = strPatientSignPath.split("/");

            saveImgDataSingle(strs[strs.length - 1].toString(), strPatientSignPath, "5");
        }

        if (TextUtils.isEmpty(strDocSignPath)) {
        } else {
            /// storage/emulated/0/PublicHealth/Sign/370883198806046521_2017-12-07_1__20171207161645_8987.png
            String[] strs = strDocSignPath.split("/");
            saveImgDataSingle(strs[strs.length - 1].toString(), strDocSignPath, "4");
        }

    }*/

   /* *//**
     * 保存图片信息单张
     *
     * @author 王婷婷
     * @date 2017年12月7日 下午3:36:59
     *//*
    private void saveImgDataSingle(String imgName, String imgPath, String str_type) {
        JTYS_SignPictureData info = new JTYS_SignPictureData();
        info.setID(GlobalContsJTYS.getUUID());
        info.setCardNum(userinfo.getIDCARD());
        info.setYsLoginNumber(SPUtil.getstr_jdrusername(LvYueJiLuActivity.this));

        info.setPhotoName(imgName);
        info.setPhotoPath(imgPath);
        info.setCreateOrgId(NovaApplication.getJgbh());
        String datetimeNow = GlobalContsJTYS.datetimeFormat.format(new Date());
        info.setCreatetime(datetimeNow);
        info.setCreaterId(SPUtil.getstr_jdrusername(this));
        info.setSign("0");
        info.setSource("0");
        info.setIsUpdate("N");// Y未上传 N已上传
        info.setRes0(str_type);
        info.setRes1(uuid);
        List<JTYS_SignPictureData> pictures = NovaApplication.fdbmanger.findAllByWhere(JTYS_SignPictureData.class,
                "CardNum = '" + userinfo.getIDCARD() + "'");
        String type = JTYS_SignPictureData.type(imgPath);
        for (JTYS_SignPictureData data : pictures) {
            if (data.type() == type) {
                NovaApplication.fdbmanger.delete(data);
                try {
                    File f = new File(data.getPhotoPath());
                    if (f.exists()) {
                        f.delete();
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
        NovaApplication.fdbmanger.save(info);
    }*/



}
